import { Request } from '../utils/request';
import { ApiResponse, UserInfo } from '../types';

export class UserApi {
  constructor(private request: Request) {}

  /**
   * 用户登录
   */
  async login(username: string, password: string): Promise<ApiResponse<{ token: string; userInfo: UserInfo }>> {
    return this.request.post('/api/user/login', { username, password });
  }

  /**
   * 获取用户信息
   */
  async getUserInfo(): Promise<ApiResponse<UserInfo>> {
    return this.request.get('/api/user/info');
  }

  /**
   * 更新用户信息
   */
  async updateUserInfo(data: Partial<UserInfo>): Promise<ApiResponse<UserInfo>> {
    return this.request.put('/api/user/info', data);
  }

  /**
   * 修改密码
   */
  async changePassword(oldPassword: string, newPassword: string): Promise<ApiResponse<void>> {
    return this.request.put('/api/user/password', { oldPassword, newPassword });
  }
} 